
import plugin from '../../../../lib/plugins/plugin.js';
import { getPlayerByE, pm } from './main.js';
import Rob from '../service/rob.js';


export class LNERobot extends plugin {
    playerManager: import("d:/QQRobot/Yunzai/Miao-Yunzai/plugins/LNERobot/ts/model/player/player_manager").default;
    constructor() {
        super({
            name: '打劫',
            dsc: '机器人',
            event: 'message',
            priority: 5,
            rule: [
                {
                    /** 命令正则匹配 */
                    reg: '^打劫.*$',
                    /** 执行方法 */
                    fnc: 'rob'
                },
            ]
        });

        this.playerManager = pm;
    }

    async rob(e) {
        if (isNaN(e.at)) {
            super.reply("请长按头像艾特，不能复制！");
            return;
        }

        let robber = await getPlayerByE(e);
        let target = await this.playerManager.getPlayerByQQNum(e.at);
        let rob = new Rob(robber, target);
        let result = await rob.do();
        if (!result.success) {
            await super.reply(result.msg);
            return;
        }


        let rpl = "";
        let flag = false;
        for (let i in result.records) {
            let count = Number.parseInt(i);
            if (count < 3 || count >= result.records.length - 3) rpl += `第${count + 1}回合\n${result.records[i].msg}\n\n`;
            else if (!flag) {
                flag = true;
                rpl += `...\n`;
            }
        }
        rpl += result.msg;

        await this.playerManager.savePlayer(robber);
        await this.playerManager.savePlayer(target);
        await super.reply(rpl);
    }

}
